home *** CD-ROM | disk | FTP | other *** search
- Path: chronicle.mti.sgi.com!news
- From: austern@isolde.mti.sgi.com (Matt Austern)
- Newsgroups: comp.lang.c++
- Subject: Re: Will JAVA kill C++?
- Date: 26 Mar 1996 20:14:27 GMT
- Organization: SGI
- Message-ID: <AUSTERN.96Mar26121428@isolde.mti.sgi.com>
- References: <313E44EA.14D110C0@netcom.com> <4hp18v$3di@frodo.smartlink.net>
- <4ht8k1$t7l@epx.cis.umn.edu> <3146278D.7703E9CC@netcom.com>
- <4i6q13$4e8@gaia.ns.utk.edu> <4j9gf5$e01@druid.borland.com>
- Reply-To: austern@mti.sgi.com
- NNTP-Posting-Host: isolde.mti.sgi.com
- In-reply-to: pete@borland.com's message of 26 Mar 1996 19:27:33 GMT
-
- In article <4j9gf5$e01@druid.borland.com> pete@borland.com (Pete Becker) writes:
-
- > >If you want to use features of C++ that theoretically ought to seem
- > >good for numerical programming, such as complex number classes and
- > >especially matrix classes, various language consequences of C++ combine
- > >to make things slower than they should be with nearly all compilers if you
- > >want to use idiomatic matrix classes.
- >
- > It turns out that this isn't necessarily true. There was a paper
- > presented by David Vandevoorde at the latest ANSI/ISO C++ meeting about
- > implementing the valarray template in a way that permitted aggressive
- > optimizations. With his changes, expressions like sum(1.2*x-2.3*y+3.4); can be
- > compiled into code that runs just as fast as the corresponding C code with
- > explicit loops, plus a bit of setup time. That's with straight gcc, not a
- > compiler that's specifically optimized for valarray.
-
- David's technique, though, relies on compile-time dispatching: in
- essence, using C++ more as a generic language (in the style of the
- STL, and of Barton and Nackman's book) than as an object-oriented
- language.
-
- Matt Kennel's concern is about using OO techniques for numerical
- programming: specifically, he's worried that if you declare a function
- to be virtual, then the compiler will do the extra work for a virtual
- function call even when the object's actual type is (or should be)
- known at compile time. This might cause serious performance problems
- in loops, unless you have a compiler that optimizes these things out.
- I don't know how common these sorts of optimizations are.
-
- In general, though, I have the same feeling about Matt's objection as
- in that old joke about the man who tells his physician "Doc, it hurts
- when I do this," and gets the response "Well, don't do that." You
- don't have to use OO techniques for numerical programming, you don't
- have to declare functions virtual, and, even if you're using someone
- else's library where everything is declared virtual, you don't have to
- use a form of function calls that implies virtual dispatch.
-
- The most important part of my last paragraph is that you don't have to
- use OO techniques at all when they're inappropriate: generic
- programming is often more useful, especially if you're interested in
- performance. C++'s greatest strength is that it supports both OOP and
- generic programming (despite C++'s weaknesses, it has better support
- for generic programming than does any other language I've seen) and
- that it lets you combine the two techniques.
- --
- Matt Austern
- SGI: MTI Compilers Group
- austern@isolde.mti.sgi.com
-